//
//  BaiXiBaoBgColorViewController.m
//  SingleDemoForAAChartKit
//
//  Created by 蓓蕾 on 2021/8/20.
//

#import "BaiXiBaoBgColorViewController.h"
#import <AAChartKit.h>

@interface BaiXiBaoBgColorViewController ()

@property (nonatomic, strong) AAChartView *aaChartView;

@property (nonatomic, strong) AAChartView *ChartView;

@property (nonatomic, strong) AAChartModel *aaChartModel;

@property (nonatomic, strong) AAOptions *aaChartOption;

@end

@implementation BaiXiBaoBgColorViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    NSLog(@"开始了");



    _aaChartView = [[AAChartView alloc]init];
    _aaChartView.frame = CGRectMake(10, 80, kScreenWidth - 20, 300);
    _aaChartView.scrollEnabled = NO;//是否允许滚动
    //_aaChartView.scrollEnabled = NO;
    [self.view addSubview:_aaChartView];
    _aaChartOption = [self configureAAPlotBandsForChart];
    [_aaChartView aa_drawChartWithOptions:_aaChartOption];
    
    
    _ChartView = [[AAChartView alloc]init];
    _ChartView.frame = CGRectMake(10, 400, kScreenWidth - 20, 300);
    _ChartView.scrollEnabled = NO;//是否允许滚动
    //_aaChartView.scrollEnabled = NO;
    [self.view addSubview:_ChartView];
    _aaChartModel = [self configureMixedLineChart];
    [_ChartView aa_drawChartWithChartModel:_aaChartModel];
}


//该写法是将两种折线图糅合成一个折线图，而实现的效果，并不推荐，推荐使用下面的方法进行实现该效果
- (AAOptions *)configureAAPlotBandsForChart {
//    AACrosshair *aaCrosshair =
//    [AACrosshair crosshairWithColor:AAColor.grayColor
//                          dashStyle:AAChartLineDashStyleTypeLongDashDotDot
//                              width:@1.5];

    AAChartModel *aaChartModel = AAChartModel.new
    .chartTypeSet(AAChartTypeLine)
//    .connectNullsSet(true)
    .markerRadiusSet(@0)//隐藏连接点
    .subtitleSet(@"虚拟数据")
    .categoriesSet(@[
        @"Java", @"Swift", @"Python", @"Ruby", @"PHP"
                   ])
    .yAxisTitleSet(@"摄氏度")
    .yAxisMinSet(@20)//设置Y轴最小值
    .colorsThemeSet(@[@"#000000",@"#000000"])
//    .dataLabelsEnabledSet(true)
    .yAxisGridLineStyleSet([AALineStyle styleWithWidth:@0])
    .seriesSet(@[
        AASeriesElement.new
        .nameSet(@"本专业")
        .dataSet(@[@45, @88, @49, @43, @70])
        .zoneAxisSet(@"x")
        .enableMouseTrackingSet(@NO)//折线图是否允许交互
        .showInLegendSet(NO)
        .lineWidthSet(@2)
        .zonesSet(@[
            AAZonesElement.new
            .valueSet(@2)
            .dashStyleSet(AAChartLineDashStyleTypeDot)
                  ]),
        AASeriesElement.new
        .nameSet(@"所有专业")
        .enableMouseTrackingSet(@NO)//折线图是否允许交互
        .showInLegendSet(NO)//是否显示图例，只针对本折线图有效
        .lineWidthSet(@2)
        .dataSet(@[@45, @88])
               ]);

    AAOptions *aaOptions = aaChartModel.aa_toAAOptions;
    aaOptions.yAxis.gridLineInterpolation = AAYAxisGridLineInterpolationPolygon;
//设置背景色
    NSArray *aaPlotBandsArr = @[
        AAPlotBandsElement.new
        .fromSet(@40)
        .toSet(@70)
        .colorSet(@"#acf08f"),
    ];

    AAYAxis *aaYAxis = aaOptions.yAxis;
    aaYAxis.plotBands = aaPlotBandsArr;
    return aaOptions;
}

- (AAChartModel *)configureMixedLineChart {
    return AAChartModel.new
    //        .connectNullsSet(true)//设置折线是否断点重连
    .chartTypeSet(AAChartTypeLine)
    .subtitleSet(@"虚拟数据")
    .categoriesSet(@[
        @"Java", @"Swift", @"PHP",
         @"C++", @"SQL"
                   ])
    .yAxisTitleSet(@"摄氏度")
    .dataLabelsEnabledSet(true)
    .yAxisGridLineStyleSet([AALineStyle styleWithWidth:@0])
    .seriesSet(@[
        AASeriesElement.new
        .nameSet(@"本专业")
        .dataSet(@[@45, @88, @49, @89, @55])
        .zoneAxisSet(@"x")
        .colorSet((id)AAGradientColor.freshPapayaColor)
        .lineWidthSet(@5)
        .zonesSet(@[
            AAZonesElement.new
            .valueSet(@2)//使用 实线 进行连接
            .dashStyleSet(AAChartLineDashStyleTypeSolid),
            AAZonesElement.new
            .valueSet(@3)//使用 点 进行连接
            .dashStyleSet(AAChartLineDashStyleTypeDot)
                  ]),
        AASeriesElement.new
        .nameSet(@"所有专业")
        .colorSet((id)AAGradientColor.pixieDustColor)
        .lineWidthSet(@5)
        .dataSet(@[@100, @109, @89, [NSNull null], @120])
               ]);
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
